<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="团号" prop="orderNumbers">
        <el-input v-model="queryParams.orderNumbers" placeholder="请输入团号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <!-- <el-form-item label="团id" prop="orderId">
        <el-input v-model="queryParams.orderId" placeholder="请输入团id" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="客人" prop="guest">
        <el-input v-model="queryParams.guest" placeholder="请输入客人" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="导游" prop="guide">
        <el-input v-model="queryParams.guide" placeholder="请输入导游" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="团队人数" prop="number">
        <el-input v-model="queryParams.number" placeholder="请输入团队人数" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="车费" prop="fare">
        <el-input v-model="queryParams.fare" placeholder="请输入车费" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="餐费" prop="meal">
        <el-input v-model="queryParams.meal" placeholder="请输入餐费" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item> -->
      <el-form-item label="录入时间" prop="enterDate">
        <el-date-picker v-model="queryParams.enterDate" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item label="录入人" prop="enterName">
        <el-input v-model="queryParams.enterName" placeholder="请输入录入人" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="审核状态" prop="approvalStatus">
         <el-select v-model="queryParams.approvalStatus" placeholder="请选择审核状态" clearable size="small">
                  <el-option v-for="dict in this.getDictDatas(DICT_TYPE.TEAM_LEDGER_APPROVAL_STATUS)"
                               :key="dict.value" :label="dict.label" :value="dict.value"/>
                </el-select>
      </el-form-item>
     <!-- <el-form-item label="审核人" prop="approvalName">
        <el-input v-model="queryParams.approvalName" placeholder="请输入审核人" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <!--<el-form-item label="审核备注" prop="approvalRemarks">
        <el-input v-model="queryParams.approvalRemarks" placeholder="请输入审核备注" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <!--<el-form-item label="备注" prop="remarks">
        <el-input v-model="queryParams.remarks" placeholder="请输入备注" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
       <el-form-item label="自定义" prop="column1">
        <el-input v-model="queryParams.column1" placeholder="请输入自定义" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="自定义" prop="column2">
        <el-input v-model="queryParams.column2" placeholder="请输入自定义" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="自定义" prop="column3">
        <el-input v-model="queryParams.column3" placeholder="请输入自定义" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="自定义" prop="column4">
        <el-input v-model="queryParams.column4" placeholder="请输入自定义" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="自定义" prop="column5">
        <el-input v-model="queryParams.column5" placeholder="请输入自定义" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="自定义" prop="column6">
        <el-input v-model="queryParams.column6" placeholder="请输入自定义" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
                   v-hasPermi="['team:finance-monad:create']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
                   v-hasPermi="['team:finance-monad:export']">导出</el-button>
      </el-col>
          <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="isEmpty(checkedIds)"
            @click="handleDeleteBatch"
            v-hasPermi="['team:finance-monad:delete']"
        >
          批量删除
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

            <el-table
			border
          v-loading="loading"
          :data="list"
          :stripe="true"
          :show-overflow-tooltip="true"
          @selection-change="handleRowCheckboxChange"
      >
        <el-table-column type="selection" width="55" />
      <!-- <el-table-column label="单子id" align="center" prop="id" /> -->
      <el-table-column label="团号" align="center" prop="orderNumbers"width="110" />
      <el-table-column label="客人" align="center" prop="guest"width="80" />
      <el-table-column label="导游" align="center" prop="guide"width="80" />
      <el-table-column label="团人数" align="center" prop="number"width="80" />
      <el-table-column label="车费" align="center" prop="fare" width="100">
		  <template v-slot="scope">
		   		<span>{{(scope.row.fare/100).toFixed(2)}}</span>   
		  </template> 
	  </el-table-column>
      <el-table-column label="餐费" align="center" prop="meal" width="100">
		  <template v-slot="scope">
		  	<span>{{(scope.row.meal/100).toFixed(2)}}</span>   
		 </template>  
	  </el-table-column>
	  <el-table-column label="录入人" align="center" prop="enterName" width="80"/>
	  <el-table-column label="凭证图片" align="center" prop="url" width="110">
		  <template v-slot="scope">
		     <image-preview  :src="scope.row.url"  :width="'100px'"></image-preview>
		  </template>
	  </el-table-column>
	  <el-table-column label="单子时间" align="center" prop="enterDate" width="110">
	    <template v-slot="scope">
	      <span>{{ parseTime(scope.row.enterDate,'{y}-{m}-{d}') }}</span>
	    </template>
	  </el-table-column>
      <el-table-column label="审核状态" align="center" prop="approvalStatus"width="80">
		  <template v-slot="scope">
		            <dict-tag :type="DICT_TYPE.TEAM_LEDGER_APPROVAL_STATUS" :value="scope.row.approvalStatus" />
		          </template>
	  </el-table-column>
      <el-table-column label="审核人" align="center" prop="approvalName" width="80"/>
      <el-table-column label="审核备注" align="center" prop="approvalRemarks" />
      <el-table-column label="审核时间" align="center" prop="column2"width="130" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
		  <el-button size="mini" type="text" icon="el-icon-delete" @click="clickAppl(scope.row)"
		             v-hasPermi="['team:ledger:clickAppl']">审核</el-button>	
          <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)"
                     v-hasPermi="['team:finance-monad:update']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['team:finance-monad:delete']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
				
	<el-dialog title="审核" :visible.sync="DialogAppl" width="30%" >
	  <div>
		  <el-form  :model="formData"  label-width="100px">
		    <el-form-item label="审核备注" >
		      <el-input type="textarea" v-model="formData.approvalRemarks" placeholder="请输入" />
		    </el-form-item>
		  </el-form>				
	  </div>
	  <span slot="footer" class="dialog-footer">
		<el-button type="primary" @click="submitAppl(2)">通过</el-button>
	    <el-button type="warning" @click="submitAppl(3)">不通过</el-button>
	  </span>
	</el-dialog>			
    <!-- 对话框(添加 / 修改) -->
    <FinanceMonadForm ref="formRef" @success="getList" />
    </div>
</template>

<script>
import * as FinanceMonadApi from '@/api/team/financemonad';
import FinanceMonadForm from './monadForm.vue';
import { mapGetters } from 'vuex'
import moment from 'moment';
import ImagePreview from "@/components/ImagePreview";
export default {
  name: "FinanceMonad",
  components: {
          FinanceMonadForm,ImagePreview
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
	   DialogAppl:false,
      // 显示搜索条件
      showSearch: true,
              // 总条数
        total: 0,
      // 录入单子管理列表
      list: [],
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
	  formData:{
	  },
      // 选中行
      currentRow: {},
      checkedIds: [],
      // 查询参数
      queryParams: {
                    pageNo: 1,
            pageSize: 10,
        orderNumbers: null,
        orderId: null,
        guest: null,
        guide: null,
        number: null,
        fare: null,
        meal: null,
        enterDate: [],
        enterName: null,
        approvalStatus: null,
        approvalName: null,
        approvalRemarks: null,
        url: null,
        remarks: null,
        column1: null,
        column2: null,
        column3: null,
        column4: null,
        column5: null,
        column6: null,
        createTime: [],
      },
            };
  },
  created() {
    this.getList();
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'nickname',
      'device'
    ]),
  },	
  methods: {
    /** 查询列表 */
    async getList() {
      try {
      this.loading = true;
              const res = await FinanceMonadApi.getFinanceMonadPage(this.queryParams);
        this.list = res.data.list;
		console.log("this.list",this.list)
        this.total = res.data.total;
      } finally {
        this.loading = false;
      }
    },
	//审核
	clickAppl(row){
		this.formData=row
		this.DialogAppl=true
	},
	//提交审核 
	async submitAppl(type){
		this.formData.approvalStatus=type;
		this.formData.approvalName=this.nickname
		this.formData.column2 = moment().format('YYYY-MM-DD HH:mm');
		try {
			if (this.formData.id) {
				console.log("提交审核数据",this.formData)
				await FinanceMonadApi.updateFinanceMonad(this.formData);
				this.$modal.msgSuccess("提交成功");
				this.DialogAppl = false;
				return;
			}	
		}finally {
			this.getList()
	    }
		
		
	},
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 添加/修改操作 */
    openForm(id) {
      this.$refs["formRef"].open(id);
    },
    /** 删除按钮操作 */
    async handleDelete(row) {
      const id = row.id;
      await this.$modal.confirm('是否确认删除录入单子管理编号为"' + id + '"的数据项?')
      try {
       await FinanceMonadApi.deleteFinanceMonad(id);
       await this.getList();
       this.$modal.msgSuccess("删除成功");
      } catch {}
    },
    /** 批量删除录入单子管理 */
    async handleDeleteBatch() {
      await this.$modal.confirm('是否确认删除?')
      try {
        await FinanceMonadApi.deleteFinanceMonadList(this.checkedIds);
        await this.getList();
        this.$modal.msgSuccess("删除成功");
      } catch {}
    },
    handleRowCheckboxChange(records) {
      this.checkedIds = records.map((item) => item.id);
    },
    /** 导出按钮操作 */
    async handleExport() {
      await this.$modal.confirm('是否确认导出所有录入单子管理数据项?');
      try {
        this.exportLoading = true;
        const data = await FinanceMonadApi.exportFinanceMonadExcel(this.queryParams);
        this.$download.excel(data, '录入单子管理.xls');
      } catch {
      } finally {
        this.exportLoading = false;
      }
    },
              }
};
</script>